﻿using System;
using System.Linq;
using System.Linq.Expressions;
using XieCan.AspMVC.Models;

namespace XieCan.AspMVC.IDAL
{
    /// <summary>
    /// 公共的数据操作接口
    /// </summary>
    /// <typeparam name="TModel">继承自BaseModel的所有类型</typeparam>
    public interface IBaseDAL<TModel> : IDALSupport where TModel : BaseModel
    {
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        OperateResult<bool> Insert(params TModel[] models);

        /// <summary>
        /// 删除实体（软删除）
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        OperateResult<bool> Delete(params TModel[] models);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        OperateResult<bool> Update(params TModel[] models);

        /// <summary>
        /// 查询实体
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        OperateResult<TModel> Model(Guid guid);

        /// <summary>
        /// 查询实体
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        OperateResult<TModel> Model(Expression<Func<TModel, bool>> where);

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        OperateResult<IQueryable<TModel>> Select();

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        OperateResult<IQueryable<TModel>> Select(Expression<Func<TModel, bool>> where);

        /// <summary>
        /// 查询列表带排序
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="where"></param>
        /// <param name="order"></param>
        /// <param name="isAsc"></param>
        /// <returns></returns>
        OperateResult<IQueryable<TModel>> Select<TKey>(Expression<Func<TModel, bool>> where, Expression<Func<TModel, TKey>> order, bool isAsc = true);

        /// <summary>
        /// 查询列表带分页
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="pageIndex">当前页面</param>
        /// <param name="pageSize">单页显示数据数量</param>
        /// <param name="rowCount">数据总数</param>
        /// <param name="where"></param>
        /// <param name="order"></param>
        /// <param name="isAsc"></param>
        /// <returns></returns>
        OperateResult<IQueryable<TModel>> Select<TKey>(Expression<Func<TModel, bool>> where, Expression<Func<TModel, TKey>> order, out int rowCount, bool isAsc = true, int pageIndex = 1, int pageSize = 12);
    }
}
